#include"ring_queue.hpp"
#include<stdlib.h>

using namespace ring_queue;


void* consumer(void* args)
{
    RingQueue<int>* rq = (RingQueue<int>*)args;
    while(true)
    {
        int data = 0;
        rq->pop(&data);
        std::cout<<"我是消费者，我消费了一个数据："<< data << std::endl;
        //sleep(1);
    }
}
void* producter(void* args)
{
    RingQueue<int>* rq = (RingQueue<int>*)args;
    while(true)
    {
        int data = rand()%20+1;
        std::cout<<"我是生产者，我生产了一个数据："<< data <<std::endl;
        rq->push(data);

        sleep(1);
    }
}

int main()
{
    RingQueue<int>* rq = new RingQueue<int>();
    pthread_t c;
    pthread_t p;
    pthread_create(&c, nullptr, consumer, (void*)rq);
    pthread_create(&p, nullptr, producter, (void*)rq);


    pthread_join(c,nullptr);
    pthread_join(p,nullptr);
}